package com.foolrabbit.springbootlearning.event;

import com.foolrabbit.springbootlearning.event.entity.Baby;
import com.foolrabbit.springbootlearning.event.service.PlaygroundCenter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    private final PlaygroundCenter playgroundCenter;

    public Application(PlaygroundCenter playgroundCenter) {
        this.playgroundCenter = playgroundCenter;

        Baby baby = new Baby("小明");
        playgroundCenter.addBaby(baby);
        baby = new Baby("小红");
        playgroundCenter.addBaby(baby);
        baby = new Baby("小刚");
        playgroundCenter.addBaby(baby);

        // 每隔5秒有个baby哭
        new Thread(() -> {
            while (true) {
                playgroundCenter.cry();
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
